package database;

public class DatabaseText extends DatabaseObject {
    public static final String LENGTH = "length";
    private int length = 256;

    public DatabaseText() {
        value = "";
    }

    @Override
    public void setValue(Object value) {
        try {
            this.value = (String) value;
        } catch (ClassCastException cce) {
            value = "";
        }
    }

    @Override
    public void setParam(String param, Object value) {
        if (param.equals(LENGTH)) {
            length = Integer.parseInt((String) value);
        }
    }

    @Override
    public Object getParam(String param) {
        if (param.equals(LENGTH)) {
            return (Object) length;
        }
        return null;
    }

    @Override
    public String toString() {
        return value.toString();
    }

    @Override
    protected void acceptValidator(Validator v) {
        v.validateText(this);
    }

    @Override
    public int compareTo(DatabaseObject o) {
        String s1 = (String) value;
        String s2 = (String) o.getValue();
        return s1.compareToIgnoreCase(s2);
    }

}
